package com.freeter.JsonUtil;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import org.apache.commons.lang3.StringUtils;


public class Txt2String {
	public static String jsonFile = "jsonfile";
	public static String txt2String(String path) {
		String root = Thread.currentThread().getContextClassLoader().getResource(jsonFile).getPath();
		String fileName = root + "/" + path;
		StringBuilder result = new StringBuilder();
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));// 构造一个BufferedReader类来读取文件
			String s = null;
			while ((s = br.readLine()) != null) {// 使用readLine方法，一次读一行

				s = StringUtils.trim(s);

				// System.lineSeparator() +
				result.append(s);
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(result.toString());
		return result.toString();
	}
	
	public static void main(String[] args) {
		System.out.println(txt2String("data.txt"));
	}
}
